using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using AtletIS.DomainModel.Entities.Web;

namespace AtletIS.Database.Mapping.Web
{
    public class DocumentMap : EntityTypeConfiguration<Document>
    {
        public DocumentMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.Title)
                .HasMaxLength(100);

            this.Property(t => t.City)
                .HasMaxLength(100);

            this.Property(t => t.Author)
                .HasMaxLength(100);

            this.Property(t => t.Path)
                .HasMaxLength(255);

            // Table & Column Mappings
            this.ToTable("Documents");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.SubcategoryId).HasColumnName("SubcategoryId");
            this.Property(t => t.Title).HasColumnName("Title");
            this.Property(t => t.Date).HasColumnName("Date");
            this.Property(t => t.City).HasColumnName("City");
            this.Property(t => t.Author).HasColumnName("Author");
            this.Property(t => t.Path).HasColumnName("Path");
            this.Property(t => t.Active).HasColumnName("Active");

            // Relationships
            this.HasOptional(t => t.DocumentsSubcategory)
                .WithMany(t => t.Documents)
                .HasForeignKey(d => d.SubcategoryId);

        }
    }
}
